package de.gameduell.framework.queue {
	import de.gameduell.framework.queue.IAction;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;	

	/**
	 * @author cbra
	 */
	public class Delay implements IAction {
		private var _delay:Number;
		private var _description:String;
		private var _queue:ActionQueue;
		
		public function Delay(aDelay:Number,aDescription:String = null, aQueue:ActionQueue = null) {
			_delay = aDelay;
			_description = aDescription =! null ? aDescription : "DummyAction";
			_queue = aQueue != null ? aQueue : SingleActionQueue.getInstance();
		}

		public function compute():void {
			var timer:Timer = new Timer(_delay, 1);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, checkActionQueue);
			timer.start();
		}
		
		public function get description():String{
			return _description;
		}
		
		public function checkActionQueue(event:TimerEvent):void{
			_queue.checkActionQueue();
		}
	}
}
